package codechicken.wirelessredstone.core;

import java.io.File;
import java.util.ArrayList;
import java.util.Properties;

import net.minecraft.client.Minecraft;
import net.minecraft.src.*;

public class CoreProxy
{
	public static void HandlePacket(PacketRedstoneEther packet, NetHandler nethandler, IWirelessPacketHandler handler)
	{
		handler.handlePacket(mc.theWorld, mc.thePlayer, packet);
	}

	public static boolean isClient()
	{
		return mc.theWorld != null && mc.theWorld.multiplayerWorld;
	}
	
	public static GuiScreen getCurrentScreen()
	{
		return mc.currentScreen;
	}
	
	public static void openTileWirelessGui(EntityPlayer entityplayer, ITileWireless tileentity)
	{
		ModLoader.OpenGUI(entityplayer, new GuiRedstoneWireless(entityplayer.inventory, tileentity));
	}
	
	public static void openItemWirelessGui(EntityPlayer entityplayer)
	{
		ModLoader.OpenGUI(entityplayer, new GuiRedstoneWireless(entityplayer.inventory));
	}
	
	private static Minecraft mc = ModLoader.getMinecraftInstance();

	public static World getWorld()
	{
		return mc.theWorld;
	}
	
	public static String getWorldName(World world)
	{
		return (world == null ? mc.theWorld : world).getWorldInfo().getWorldName();
	}
	
	public static File getWorldDirectory(World world, int dimension)
	{
		String subdimension = "";
		if(dimension != 0)
		{
			subdimension = File.separator + "DIM" + dimension;
		}
		return new File(Minecraft.getMinecraftDir() + File.separator + "saves" + File.separator + getWorldName(world) + subdimension);
	}
	
	public static boolean isSMP()
	{
		return false;
	}

	public static EntityPlayer getPlayer()
	{
		return mc.thePlayer;
	}

	public static EntityPlayer getPlayer(String playername)
	{
		return playername == mc.thePlayer.username ? mc.thePlayer : null;
	}

	public static File getMinecraftDir()
	{
		return Minecraft.getMinecraftDir();
	}
	
	public static void sendPacket(Packet packet)
	{
		mc.getSendQueue().addToSendQueue(packet);
	}

	public static World getWorld(int dimension)
	{
		return null;
	}
	
	public static int getArrayDimension(World world)
	{
		if(world.worldProvider.isNether)
		{
			return 1;
		}
		else
		{
			return 0;
		}
	}
	
	public static int getActualDimension(World world)
	{
		if(world.worldProvider.isNether)
		{
			return -1;
		}
		else
		{
			return 0;
		}
	}
	
	public static int getArrayDimension(int dimension)
	{
		if(dimension == -1)
		{
			return 1;
		}
		return 0;
	}

	public static int getActualDimension(int dimension)
	{
		if(dimension == 1)
		{
			return -1;
		}
		return 0;
	}

	public static ArrayList<EntityPlayer> getAllPlayers()
	{
		return null;
	}

	public static ArrayList<EntityPlayer> getPlayersInDimension(int actualDimension)
	{
		return null;
	}
	
	public static void AddLocalization(String s, String s1)
    {
        Properties properties = null;
        try
        {
            properties = (Properties)ModLoader.getPrivateValue(net.minecraft.src.StringTranslate.class, StringTranslate.getInstance(), 1);
        }
        catch(SecurityException securityexception)
        {
            ModLoader.ThrowException("Wireless Redstone Localization", securityexception);
        }
        catch(NoSuchFieldException nosuchfieldexception)
        {
            ModLoader.ThrowException("Wireless Redstone Localization", nosuchfieldexception);
        }
        if(properties != null)
        {
            properties.put(s, s1);
        }
    }
}
